import { Component, OnInit } from '@angular/core';
import {ActivatedRoute, Router} from "@angular/router";
import {GetOrginizationService} from "../../../../share/services/get-orginization.service";
import {Location} from '@angular/common'

@Component({
  selector: 'app-regional-overview',
  templateUrl: './regional-overview.component.html',
  styleUrls: ['./regional-overview.component.css']
})
export class RegionalOverviewComponent implements OnInit {
  orgList: object[] = [];
  id: number ;
  regionOrgLogoSrc: string = '';
  totalKks:string;
  capacity: number=0;
  public hotspots: object[]=[];
  public startTime:string = '';
  public endTime:string = '';
  constructor(
    private router: Router,
    private activeRoute : ActivatedRoute,
    private getOrg:GetOrginizationService,
    private location:Location
  ) {
    this.id = +activeRoute.snapshot.params['id'];
    this.startTime = activeRoute.snapshot.params['startTime'];
    this.endTime = activeRoute.snapshot.params['endTime'];
  }
  ngOnInit() {
    console.debug('RegionalOverviewComponent init')
    this.initOrgInfo()
  }

  initOrgInfo() {

    this.getOrg.getOrgById(this.id).subscribe(
      regional => {
        this.totalKks=regional.totalkks
        this.orgList=regional.stationSet;
        // console.log(orgList)
        let capa=0;
        if(regional.stationSet){
          regional.stationSet.forEach(station=>{
            if(station.wtSet ){
              let  stationCapa=0
              station.wtSet.forEach(wt=>{
                stationCapa+=wt.capacity
                capa+=wt.capacity;
              })
              this.hotspots.push({
                id:station.id,
                capacity:station.nameForShort+'装机容量:'+ (stationCapa/10000).toFixed(3) +'MW'
              })
            }
          });
          this.capacity=capa;
          this.hotspots.forEach((pot,index)=>{
            let left:number=10,bottom:number=10;
            switch (+pot['id']){
              case 308:left=80;bottom=50;break;//义和他拉
              case 307:left=80;bottom=40;break;//北清河
              case 309:left=85;bottom=45;break;//代力吉

              case 306:left=50;bottom=50;break;//二连浩特
              case 295:left=58;bottom=45;break;//乌宁巴图
              case 291:left=50;bottom=42;break//库伦
              case 290:left=50;bottom=35;break//辉腾锡勒
              case 297:left=43;bottom=40;break//红泥井
              case 298:left=40;bottom=33;break//巴音
              case 300:left=30;bottom=35;break//川井嘉合
            }
            pot['left']=left+'%';
            pot['bottom']=(bottom-15)+'%'
          })
        }
      }
    )

  }
  public staticTime:number=2;

  freshTime(startTime:string){
    let arr = startTime.split(";")
    this.startTime = arr[0];
    this.endTime = arr[1];
  }
  public goBack(flag?:boolean){
    if(flag){
      this.location.back()
    }
    else {
      this.router.navigate(['/pages/home'])
    }
  }
}
